<template>
  <div class="pagestyle">
    <list_controller
      :style="{ width: state.listBtnType == 6 ? '78%' : '100%' }"
      ref="zujianname"
      :options="state.options"
      :showCaozuo="true"
      @query="query"
      @pagechange="pagechange"
    >
      <template v-slot:selectNamelist> 瓦斯班次查询 </template>
    </list_controller>
  </div>
</template>

<script setup>
import list_controller from "@/components/commonCom/list_controller";
import { computed, reactive } from "vue";
import { table_headers } from "@/components/commonCom/table_headers";
import axios from "@/utils/request";
import usePagesStore from "@/store/modules/pages";
import { searchareaTree } from "@/api/config";
import dayjs from "dayjs";
const { proxy } = getCurrentInstance();
const store = usePagesStore();
const router = useRouter();
let previewHttps = import.meta.env.VITE_APP_HTTP;
const upload = ref(null);
let state = reactive({
  listBtnType: undefined,
  options: {
    tableheads: computed(() => table_headers.hisHourDetailInfo),
    queryList: {
      autoSearch: true,
      querys: [
        {
          field: ["startTime", "endTime"],
          fieldsearch: ["startTime", "endTime"],
          title: "时间范围",
          col: 12,
          type: "datetimestartEnd",
          binddata: [
            dayjs().subtract(1, "day").format("YYYY-MM-DD HH:mm:ss"),
            dayjs().format("YYYY-MM-DD HH:mm:ss"),
          ],
          show: true,
        },
        {
          field: "datetime",
          fieldsearch: "datetime",
          title: "日期",
          type: "datetime",
          binddata: dayjs().format("YYYY-MM-DD"),
        },
        {
          fieldsearch: "banci",
          field: "banci",
          title: "班次选择",
          type: "selectspecial",
          binddata: "",
          options: [],
        },
        {
          field: "area",
          title: "所在区域",
          type: "cascaderRadionarmal",
          binddata: "",
          options: [],
          props: {
            children: "childList",
            value: "areaName",
            label: "areaName",
            checkStrictly: true,
            emitPath: false,
          },
        },
        {
          field: "condition",
          fieldSpecial: "condition",
          title: "测点类型",
          type: "cascaderRadio",
          binddata: "A",
          options: [],
          props: {
            children: "children",
            value: "code",
            label: "name",
            checkStrictly: true,
            emitPath: false,
          },
          show: true,
        },
        {
          field: "isGas",
          title: "测点类型",
          type: "cascaderRadio",
          binddata: true,
          show: true,
        },
        {
          field: "pointId",
          title: "选择测点",
          type: "cascaderRadioSpecial",
          binddata: "",
          options: [],
          props: {
            children: "children",
            value: "commonField",
            label: "commonField",
            checkStrictly: false,
            emitPath: false,
          },
        },
        {
          field: "rate",
          title: "查询方式",
          type: "radiospecial",
          binddata: 0.2,
          options: [
            {
              label: ">0.2%",
              value: 0.2,
            },
            {
              label: ">0.5%",
              value: 0.5,
            },
          ],
        },
      ],
    },
    dataUrl: "/hisPointHour/listDetailTimeInfo",
  },
  tempList: [],
  // 表单
  editId: undefined,
  drawerShow: false,
  pointDataList: [],
  banciObj: "",
  descObj: {},
  banciList: [],
});
function getSelList() {
  searchareaTree().then((res) => {
    state.options.queryList.querys.forEach((item) => {
      if (item.field == "area") {
        item.options = res.data;
      }
    });
  });
}
getSelList();
function getbanciList() {
  axios.post("/class/info/searchAll", {}).then((res) => {
    state.banciObj = res.data.list[0];
    state.banciList = res.data.list;
    state.options.queryList.querys.forEach((item) => {
      if (item.fieldsearch == "banci") {
        item.options = res.data.list.map((item) => {
          return {
            label: item.className,
            value: item.id,
          };
        });
        item.binddata = item.options[0].value;
      }
    });
    banciList({
      classInfo: state.banciObj,
      dateSuffix: state.options.queryList.querys[1].binddata,
    });
  });
}
getbanciList();
function getconditionList(dataObj) {
  axios.post("/hisPointFeed/conditionList", dataObj).then((res) => {
    state.options.queryList.querys.forEach((item) => {
      res.data.forEach((item2) => {
        if (item.type == "cascaderRadioSpecial" && item2.sensorName == "瓦斯") {
          item.options = [item2];
        }
      });
    });
  });
}
getconditionList({
  condition: "A",
});

const query = (obj) => {
  console.log(obj);

  if (obj.type == "topConnectBom") {
    state.descObj = obj.data;
  } else if (obj.type == 5) {
    let dataObj = {
        dateSuffix: undefined,
        classInfo: {},
      };
    state.options.queryList.querys.forEach((item) => {
        if (obj.val1) {
          dataObj.dateSuffix = obj.val1
          if (item.fieldsearch == "banci") {
            state.banciList.forEach((itemsub) => {
              if (itemsub.id == item.binddata) {
                dataObj.classInfo = itemsub;
                dataObj.typeLabel=2
                banciList(dataObj);
              }
            });
          }
        } else {
          if (item.fieldsearch == "datetime") {
            dataObj.dateSuffix = item.binddata;
          }
        }
        if (item.fieldsearch == "banci") {
          state.banciList.forEach((itemsub) => {
            if (obj .val == 0) {
              obj.val = state.banciList[0].id
            }
            if (itemsub.id == obj.val) {
              dataObj.classInfo = itemsub;
              dataObj.typeLabel=2
              banciList(dataObj);
            }
          });
        }
      });
  }
};

function banciList(dataObj) {
  axios.post("/hisPointFeed/handleClassInfo", dataObj).then((res) => {
    state.options.queryList.querys.forEach((item) => {
      if(dataObj.typeLabel!=2||state.options.queryList.querys[0].binddata==2){
        if (item.type == "datetimestartEnd") {
          item.binddata = [res.data.feedStartTime, res.data.feedEndTime];
        }
      }
    });
  });
}
function pagechange() {
  proxy.$refs.zujianname.getData({
    ...state.descObj,
  });
}
</script>
<style lang="scss" scoped>
.xiazai {
  position: absolute;
  top: 42px;
  right: 241px;
  width: 120px;
  height: 64px;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: space-between;
  background-color: #ffff;
  box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.12);
  border-radius: 2px;
  z-index: 99;

  .item {
    width: 100%;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .item:hover {
    background-color: #ececec;
  }
}

.pagestyle {
  display: flex;
  justify-content: space-between;
}
</style>
